<?php
	require_once("conexion/conexion.php");
	function BuscaCCultivos($area,$rut)
	{
		$con = new Conexion();
		$con2 = $con->conexionBD("fpproduccion");
		$sql="select CCCod from centrocultivo cc inner join areaextraccion ae on ae.aecod=cc.aecod where cc.aecod='".$area."' and cc.CliRut='".$rut."' and CCEstado=0 order by CCCod asc";
		$res= mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
		$fila = mysql_num_rows($res);
		$con->cerrarBD();
		$cadena = "";
		$aux=0;
		while($reg = mysql_fetch_array($res))
		{
			if($aux==0)
			{
				$aux=1;
				$cadena = $reg['CCCod'];
			}
			else
			{
				$cadena = $cadena."<br>".$reg['CCCod'];
			}
		}
		
		return $cadena;
	}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Documento sin t&iacute;tulo</title>
<link href="Estilos/global.css" rel="stylesheet" type="text/css" />
<link href="Estilos/local.css" rel="stylesheet" type="text/css" />
<link href="Estilos/CssTabla3.css" rel="stylesheet" type="text/css" />

<script src="include_js/jquery.js" type="text/javascript"></script>
<script>
function EditarStock(valor)
{
	codigo = document.getElementById("tbBodega").rows[valor].cells[1].innerText;
	nombreArea = document.getElementById("tbBodega").rows[valor].cells[0].innerText;
	cliente = document.getElementById("tbBodega").rows[valor].cells[2].innerText;
	$.ajax({
				type: 'POST',
				url: 'Editar/Carga_Editar_CCultivo.php',
				data: {codigo:codigo,cliente:cliente,nombreArea:nombreArea},
				success: function(data) {
					$('#tabla2').html(data);
				}
			})
}
</script>
</head>

<body>
<form name="analisis" id="analisis" method="post">
<?php
		$con = new Conexion();
		$con2 = $con->conexionBD("fpproduccion");
		$sql="select distinct
					AENombre,
					cc.AECod,
					CliRSocial,
					cc.CliRut
					
					from centrocultivo cc
					inner join areaextraccion ae on
					ae.AECod=cc.AECod
					inner join clientes c on
					c.clirut=cc.clirut where 1 order by ae.AECod";
		$res= mysql_query($sql) or die ($con->error_mysql("Error en la consulta".mysql_error()));
		$con->cerrarBD();
?>
<div style="height:5px"></div>
<div class='option2'><label style="font:Verdana, Arial, Helvetica, sans-serif; color:#0066CC; font-weight:bold;">Centros de Cultivos Ingresados.</label><div style="display:inline; margin-left:490px;"><img src="imagen/cerrar.png" width="16" height="16" onclick="CerrarDatos();" style="cursor: pointer; border: 1px solid #990000;" alt="Cerrar" /></div></div>
  <div class="cabecera">
   <table class="fija" border="0" cellpadding="0" cellspacing="0" id="tbBodega">
      <thead class="fija">
      	<tr class="fija">
      	  <th width="28%" class="fija">area</th>
      	  <th width="12%" class="fija">cod</th>
      	  <th width="41%" class="fija">cliente</th>
		  <th width="19%" class="fija">c. cultivos</th>
		  <th class="fija">&nbsp;</th>
      	</tr>
      </thead>
      <tbody class="fija">
         <tr class="fija"><td colspan="5" class="fija">&nbsp;</td></tr>
		 <?php
		$aux = 2;
		while($reg = mysql_fetch_array($res))
		{
			$cc = BuscaCCultivos($reg['AECod'],$reg['CliRut']);
			if($cc!='')
			{
			if(($aux % 2)==0)
			{
				echo "<tr class='filaImpar' id='".$aux."'>";
				echo "<td width=\"28%\" style='text-align:lefth;padding-left:20px;'>".$reg['AENombre']."</td>";
				echo "<td width=\"12%\" style='text-align:center'>".$reg['AECod']."</td>";
				echo "<td width=\"41%\" style='text-align:lefth;padding-left:20px;'>".$reg['CliRSocial']."</td>";
				echo "<td width=\"19%\" style='text-align:lefth;padding-left:30px;'>".$cc."</td>";
				echo "<td style='text-align:center'><img src='imagen/edit_icon.gif' width='16' height='16' alt='Editar' style='cursor: pointer;' onclick='EditarStock($aux);'/></td>";
				echo "</tr>";
			}
			else
			{
				echo "<tr class='filaPar' id='".$aux."'>";
				echo "<td width=\"28%\" style='text-align:lefth;padding-left:20px;'>".$reg['AENombre']."</td>";
				echo "<td width=\"12%\" style='text-align:center'>".$reg['AECod']."</td>";
				echo "<td width=\"41%\" style='text-align:lefth;padding-left:20px;'>".$reg['CliRSocial']."</td>";
				echo "<td width=\"19%\" style='text-align:lefth;padding-left:30px;'>".$cc."</td>";
				echo "<td style='text-align:center'><img src='imagen/edit_icon.gif' width='16' height='16' alt='Editar' style='cursor: pointer;' onclick='EditarStock($aux);'/></td>";
				echo "</tr>";
			}
			$aux++;
			}
		}
		?>
      </tbody>
   </table>       
</div>
<div id="eliminar"></div>
</form>
</body>
</html>
